//
//  DynamicMomentView.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/10.
//

import SwiftUI

struct DynamicMomentView: View {
    @EnvironmentObject var appState: AppState
    @StateObject var profileModel = profileViewModel()
    @State var images:[String] = ["tianjia","21","21","21","21","21"]
    var body: some View {
        VStack {
            HStack {
                Button(action: {
                    appState.navigateBack()
                }) {
                    Image("back")
                }
                .frame(width: 16,height: 16)
                Spacer()
                Text("运动圈")
                    .font(.system(size: 18))
                    .foregroundStyle(.white)
                Spacer()
                Button(action: {
                    appState.navigateTo(.postSportMoment)
                }) {
                    Image("posticon")
                }
                .frame(width: 24,height: 24)
            }
            .padding(.horizontal,12)
            .frame(height: 44)
            .padding(.top,44)
            Spacer().frame(height: 20)
            ScrollView (.horizontal,showsIndicators: false) {
                HStack(spacing: 22) {
                    ForEach(images, id: \.self) { name in
                        if let uiImage = UIImage(named: name) {
                            Image(uiImage: uiImage)
                                .resizable()
                                .aspectRatio(contentMode: .fit)
                                .frame(width: 49, height: 49)
                        } else {
                            Color.gray
                                .frame(width: 49, height: 49)
                                .overlay(Text("缺失图片"))
                        }
                    }
                }.padding(.horizontal,20)
            }
            
            Spacer().frame(height: 20)
            
            ScrollView(.vertical,showsIndicators: false) {
                ForEach($profileModel.dynamicList, id: \.dynamicId) { $item in
                    SportsCircleView(dynamicitem: $item)
                }
            }
            Spacer()
        }
        .navigationBarHidden(true)
        .background(Color(hex: "#0A0A0A"))
        .edgesIgnoringSafeArea(.all)
        .onAppear {
            profileModel.getDynamicListData()
        }
    }
}

#Preview {
    DynamicMomentView()
}
